package display;

import java.awt.Color;
import java.awt.Container;
import java.awt.Graphics;

import javax.swing.JPanel;

import universe.Board;
import universe.Cell;
import universe.Game;

public class BoardDisplay extends JPanel{

	private Board  theBoard;
	private Container theContainerGame;

	public BoardDisplay(Container pContainerGame, Game pGame){
		super();
		this.theContainerGame = pContainerGame;
		this.theBoard = pGame.getBoard();
		this.setSize(display.Utils.getBoardWidthPx()+Utils.paddingFrame, display.Utils.getBoardHeightPx()+Utils.paddingFrame);
		theContainerGame.add(this);

	}




	public void paintComponent(Graphics g){

		
		Color theColor = new Color(Utils.boardColor.getRed(), Utils.boardColor.getGreen(), Utils.boardColor.getBlue(), display.Utils.boardAlpha);
		g.setColor(theColor);
		g.fill3DRect(Utils.paddingFrame, Utils.paddingFrame, Utils.getBoardWidthPx(), Utils.getBoardHeightPx(),true);


		Cell[][] matrix = theBoard.getMatrix();
		for(int i=0; i<theBoard.getWidth();i++){
			for(int j=0; j<theBoard.getHeight();j++){
				if(matrix[i][j] != null){
					g.setColor(Utils.getColor(matrix[i][j].getColorNumber()));
						g.fill3DRect(Utils.paddingFrame+i*Utils.sideWidth, Utils.paddingFrame+j*Utils.sideWidth, Utils.sideWidth, Utils.sideWidth,true);
				}
			}	
		}
	}

}
